// SDIMenuDemoView.cpp : implementation of the CSDIMenuDemoView class
//

#include "stdafx.h"
#include "SDIMenuDemo.h"

#include "SDIMenuDemoDoc.h"
#include "SDIMenuDemoView.h"
#include "resource.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSDIMenuDemoView

IMPLEMENT_DYNCREATE(CSDIMenuDemoView, CView)

BEGIN_MESSAGE_MAP(CSDIMenuDemoView, CView)
	ON_WM_CONTEXTMENU()
	//{{AFX_MSG_MAP(CSDIMenuDemoView)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSDIMenuDemoView construction/destruction

CSDIMenuDemoView::CSDIMenuDemoView()
{
	// TODO: add construction code here

}

CSDIMenuDemoView::~CSDIMenuDemoView()
{
}

BOOL CSDIMenuDemoView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CSDIMenuDemoView drawing

void CSDIMenuDemoView::OnDraw(CDC* pDC)
{
	CSDIMenuDemoDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	// TODO: add draw code for native data here
	pDC->TextOut(10,20,"Right Click On View...");
}

/////////////////////////////////////////////////////////////////////////////
// CSDIMenuDemoView printing

BOOL CSDIMenuDemoView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CSDIMenuDemoView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CSDIMenuDemoView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CSDIMenuDemoView diagnostics

#ifdef _DEBUG
void CSDIMenuDemoView::AssertValid() const
{
	CView::AssertValid();
}

void CSDIMenuDemoView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CSDIMenuDemoDoc* CSDIMenuDemoView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSDIMenuDemoDoc)));
	return (CSDIMenuDemoDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CSDIMenuDemoView message handlers

void CSDIMenuDemoView::OnContextMenu(CWnd*, CPoint point)
{

	// CG: This block was added by the Pop-up Menu component
	{
		if (point.x == -1 && point.y == -1){
			//keystroke invocation
			CRect rect;
			GetClientRect(rect);
			ClientToScreen(rect);

			point = rect.TopLeft();
			point.Offset(5, 5);
		}

		CCJMenu menu;
		VERIFY(menu.LoadMenu(IDR_MAINFRAME));
		menu.LoadToolbar(IDR_MAINFRAME);

		//CCJMenu* pPopup = menu.GetSubMenu(0);
		CCJMenu* pPopup = (CCJMenu*)menu.GetSubMenu(0);
		ASSERT(pPopup != NULL);
		CWnd* pWndPopupOwner = this;

		while (pWndPopupOwner->GetStyle() & WS_CHILD)
			pWndPopupOwner = pWndPopupOwner->GetParent();

		pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,
			pWndPopupOwner);
	}
}
